public class HashBucket {
   static class Node{
       private int key;
       private int value;
       private Node next;

       public Node(int key, int value) {
           this.key = key;
           this.value = value;
       }
   }

   public Node[] array;
   public int usedSize;

   private static final float DEFAULT_LOAD_FACTOR = 0.75f;

   public HashBucket(){
       this.array = new Node[10];
   }

   public void put(int key,int val){
       Node node = new Node(key,val);
       int index = key % array.length;
       //遍历index位置下面的链表
       Node cur = array[index];
       while (cur != null){
           if (cur.key == key){
               cur.value = val;
               return;
           }
           cur = cur.next;
       }
       //cur == null 进行头插法
       node.next = array[index];
       array[index] = node;
       usedSize++;

       //计算负载因子
       if (loafFactor() >= DEFAULT_LOAD_FACTOR){

       }
   }



   //重新哈希原来的数据
    private void resize(){
       //2倍扩容
       Node[] tmpArray = new Node[array.length*2];
       //遍历原来的数组，下标的每个链表
        for (int i = 0; i < array.length;i++){
            Node cur = array[i];
            while (cur != null){
                Node curNext = cur.next;//需要原来链表的下一个节点的位置
                int index = cur.key % tmpArray.length;//新数组的位置
                //采用头插法 放到新数组的index位置
                cur.next = tmpArray[index];//这里修改之后cur的next已经变了
                tmpArray[index] = cur;
                cur = curNext;
            }
        }

        array = tmpArray;
    }

   private float loafFactor(){
       return usedSize * 1.0f / array.length;
   }

   //通过key值，返回value
   public int get(int key){
       //怎么放的怎么取
       int index = key % array.length;
       Node cur = array[index];
       while (cur != null){
           if (cur.key == key){
              return cur.value;
           }
           cur = cur.next;
       }
       return -1;
   }








}
